<?php
/**
 * Created by PhpStorm.
 * User: extraxue
 * Date: 2018/5/6
 * Time: 下午11:58
 */
?>

<?php
error_reporting(E_ALL ^ E_NOTICE); ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>
    <title>通知板</title>
</head>


<?php
session_start();
header('Content-type:text/html;charset=utf8');
require_once('pdo.php');

$sqlGetNewsType = "select * from news_type_info a where a.status = '1' order by uid asc";
$rsGetNewsType = $pdo->query($sqlGetNewsType);
$resultGetNewsType = $rsGetNewsType->fetch(PDO::FETCH_ASSOC);
?>

<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>新闻编辑</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="newsReEdit.php">
            <div class="form-group" style="margin-top: 30px;">
                <div class="label">
                    <label>选择新闻类别：</label>
                </div>
                <div class="field">
                    <select class="input" name="newsType" style="width: 200px" ">
                    <option value='all'>全部</option>
                    <?php
                    foreach ($pdo->query($sqlGetNewsType) as $key => $resultGetNewsType) {
                        echo "<option value='$resultGetNewsType[news_type_name]'>$resultGetNewsType[news_type_name]</option>";
                    }
                    ?>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>文章标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input" name="newsTitle" size="50" placeholder="支持模糊查询"
                           style="width:200px"/>
                </div>
            </div>
            <div class="form-group ">
                <div class="label">
                    <!--                此div做格式化用无实际意义-->
                </div>
                <div class="field" style="padding-top: 20px;">
                    <button class="button bg-main icon-check-square-o" type="submit">查询</button>
                </div>
            </div>
        </form>
    </div>
</div>

<?php
$newsType = $_POST['newsType'];
$newsTitle = $_POST['newsTitle'];

if ($newsType == 'all' && $newsTitle) {
    $sqlGetNewsInfo = "select * from news_info a where a.news_title like '%{$newsTitle}%' and a.status='1'";
    $rsGetNewsInfo = $pdo->query($sqlGetNewsInfo);
    $resultGetNewsInfo = $rsGetNewsInfo->fetch(PDO::FETCH_ASSOC);
    if ($resultGetNewsInfo) {
        foreach ($pdo->query($sqlGetNewsInfo) as $key => $resultGetNewsInfo) {
            ?>
            <div style="height: 20px"></div>
            <div class="dialog open">
                <div class="dialog-head">
                    <span class="dialog-close rotate-hover"></span>
                    <strong>文章标题：</strong>
                    <span style="color: #C50C11;font-size: 16px">
                <?php echo "$resultGetNewsInfo[news_title]" ?></span>
                    <a href="newsChange.php?uid=<?= $resultGetNewsInfo['uid'] ?>"
                       class="button button-little bg-yellow" style="padding: 5px 10px;margin-left: 10px;float: right">
                        <span class="icon-power-off">修改</span></a>
                    <a href="newsDelete.php?uid=<?= $resultGetNewsInfo['uid'] ?>"
                       class="button button-little bg-red" style="padding: 5px 10px;margin-left: 10px;float: right">
                        <span class="icon-power-off">删除</span></a>
                </div>
                <div class="dialog-body">
                    文章作者：<strong><?php echo "$resultGetNewsInfo[news_author]" ?></strong>
                </div>
                <div class="dialog-body">
                    文章类别：<strong><?php echo "$resultGetNewsInfo[news_type]" ?></strong>
                </div>
                <div class="dialog-body">
                    发布时间：<strong><?php echo "$resultGetNewsInfo[create_time]" ?></strong>
                </div>
                <div class="dialog-body">
                    文章摘要：
                    <p></p><strong><?php echo mb_substr($resultGetNewsInfo['news_content'], 0, 100, "utf-8") ?></strong>......
                </div>

            </div>
            <?php
        }
    } else {
        ?>
        <div class="alert alert-red" style="margin-top: 20px;"><span class=""></span><strong>未查询到该新闻信息</strong>
            <p> 请重新操作。</p>
        </div>

        <?php
    }
}

if ($newsType <> 'all' && $newsTitle) {

    $sqlGetNewsInfo = "select * from news_info a where a.news_title like '%{$newsTitle}%' and a.news_type='{$newsType}' and a.status='1'";
    $rsGetNewsInfo = $pdo->query($sqlGetNewsInfo);
    $resultGetNewsInfo = $rsGetNewsInfo->fetch(PDO::FETCH_ASSOC);
    if ($resultGetNewsInfo) {
        foreach ($pdo->query($sqlGetNewsInfo) as $key => $resultGetNewsInfo) {
            ?>
            <div style="height: 20px"></div>
            <div class="dialog open">
                <div class="dialog-head">
                    <span class="dialog-close rotate-hover"></span>
                    <strong>文章标题：</strong>
                    <span style="color: #C50C11;font-size: 16px">
                <?php echo "$resultGetNewsInfo[news_title]" ?></span>
                    <a href="newsChange.php?uid=<?= $resultGetNewsInfo['uid'] ?>"
                       class="button button-little bg-yellow" style="padding: 5px 10px;margin-left: 10px;float: right">
                        <span class="icon-power-off">修改</span></a>
                    <a href="newsDelete.php?uid=<?= $resultGetNewsInfo['uid'] ?>"
                       class="button button-little bg-red" style="padding: 5px 10px;margin-left: 10px;float: right">
                        <span class="icon-power-off">删除</span></a>
                </div>
                <div class="dialog-body">
                    文章作者：<strong><?php echo "$resultGetNewsInfo[news_author]" ?></strong>
                </div>
                <div class="dialog-body">
                    文章类别：<strong><?php echo "$resultGetNewsInfo[news_type]" ?></strong>
                </div>
                <div class="dialog-body">
                    发布时间：<strong><?php echo "$resultGetNewsInfo[create_time]" ?></strong>
                </div>
                <div class="dialog-body">
                    文章摘要：
                    <p></p><strong><?php echo mb_substr($resultGetNewsInfo['news_content'], 0, 100, "utf-8") ?></strong>......
                </div>

            </div>

            <?php
        }
    } else {
        ?>
        <div class="alert alert-red" style="margin-top: 20px;"><span class=""></span><strong>未查询到该新闻信息</strong>
            <p> 请重新操作。</p>
        </div>
        <?php
    }
}
?>

</body>
</html>